//
// Created by Administrator on 2023/8/4.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<int> sortEvenOdd(vector<int> &nums) {
        vector<int> odds;
        vector<int> evens;
        for (int i = 0;i<nums.size();++i) {
            if (i % 2 == 0) {
                evens.push_back(nums[i]);
            } else {
                odds.push_back(nums[i]);
            }
        }
        sort(odds.begin(), odds.end(), greater<>());
        sort(evens.begin(), evens.end());
        vector<int> ans(nums.size(), 0);
        for (int i = 0; i < ans.size(); ++i) {
            if (i % 2 == 0) {
                ans[i] = evens[i / 2];
            } else
                ans[i] = odds[i / 2];
        }
        return ans;
    }
};


int main() {
    Solution s;
    vector<int> nums = {36, 45, 32, 31, 15, 41, 9, 46, 36, 6, 15, 16, 33, 26, 27, 31, 44, 34};
    auto ans = s.sortEvenOdd(nums);
    for (auto &x: ans) cout << x << ' ';
    return 0;
}